package main

import "fmt"

type Account struct {
	AccountNo string
	Pwd       string
	Balance   float64
}

func (account *Account) Deposite(money float64, pwd string) {
	if pwd != account.Pwd {
		fmt.Println("输入的密码不正确")
		return
	}
	if money <= 0 {
		fmt.Println("输入的金额不正确")
		return
	}
	account.Balance += money
	fmt.Println("存款成功")
}
func (account *Account) WithDraw(money float64, pwd string) {
	if pwd != account.Pwd {
		fmt.Println("输入的密码不正确")
		return
	}
	if money <= 0 || money > account.Balance {
		fmt.Println("输入的金额不正确")
		return
	}
	account.Balance -= money
	fmt.Println("取款成功")
}

func (account *Account) Query(pwd string) {
	if pwd != account.Pwd {
		fmt.Println("输入的密码不正确")
		return
	}
	fmt.Printf("账号为%v 余额为%v \n", account.AccountNo, account.Balance)
}

func main() {
	//测试Account方法
	account := Account{
		AccountNo: "gsyh",
		Pwd:       "666",
		Balance:   100.0,
	}
	menu := 1
	pass := ""
	money := 0.0
	for {
		fmt.Println("输入您需要办理的功能 1.查询 2.存款 3.取款 4.退出系统")
		fmt.Scanln(&menu)
		switch menu {
		case 1:
			fmt.Println("请输入密码")
			fmt.Scanln(&pass)
			account.Query(pass)
			continue
		case 2:
			fmt.Println("请输入密码")
			fmt.Scanln(&pass)
			fmt.Println("请输入存款金额")
			fmt.Scanln(&money)
			account.Deposite(money, pass)
			continue
		case 3:
			fmt.Println("请输入密码")
			fmt.Scanln(&pass)
			fmt.Println("请输入取款金额")
			fmt.Scanln(&money)
			account.WithDraw(money, pass)
			continue
		}
		break
	}

}
